﻿using System; 
using System.Collections.Generic; 
using System.ComponentModel; 

namespace DataAccess{
[Serializable]
[GenWiseAttribute(IsDataSourceEntity = true) ]
public class comment : INotifyPropertyChanged
 {


#region --- Class Fields / Objects  ---

[NonSerialized]
protected PropertyChangedEventHandler _propertyChanged;
private System.Int32 _id;
private System.DateTime? _date;
private System.String _contents;
private System.Int32? _user_id;
private System.Int32? _forum_id;
private System.Int32? _art_id;
private System.Int32? _comment_id;
private IList<comment> _commentChild;
private art _art;
private comment _commentParent;
private forum _forum;
private user _user;

#endregion


#region --- Class Properties ---

public virtual System.Int32 id 
{
get
{
return _id;
}
}

/// <summary>
/// This property contains a calculated, bindable value of the DATE part of a DateTime property. If you want to only work with the DATE and ignore the underlying TIME component then you could use this property.
/// </summary>
/// <remarks>
/// Auto-Generated Property
/// </remarks>
public virtual System.String date_Date 
{
get
{
if (  !date.HasValue ) 
{ 
 return String.Empty;
} 
else 
{ 
if ( date.Value.ToShortDateString() == System.DateTime.MinValue.ToShortDateString() ) 
 return String.Empty;
else  
 return date.Value.ToShortDateString();
} 

}
set 
{
if ( string.IsNullOrEmpty( value ) )  
{
 if (string.IsNullOrEmpty(date_Time)) {

date = null;
}
 else
{
 date = Convert.ToDateTime( " " + System.DateTime.MinValue.ToShortDateString() + " " + date.Value.ToString("HH:mm:ss.fff") ) ;
}
}
 else
{
 if (string.IsNullOrEmpty(date_Time)) 
{
 date = Convert.ToDateTime( " " + value + " " + System.DateTime.MinValue.ToLongTimeString() ) ;
}
 else
{
 date = Convert.ToDateTime( " " + value + " " + date.Value.ToString("HH:mm:ss.fff") ) ;
}
}

}
}

/// <summary>
/// This property contains a calculated, bindable value of the TIME part of a DateTime property. If you want to only work with the TIME and ignore the underlying DATE component then you could use this property.
/// </summary>
/// <remarks>
/// Auto-Generated Property
/// </remarks>
public virtual System.String date_Time 
{
get
{
if (  !date.HasValue ) 
{ 
 return String.Empty;
} 
else 
{ 
if ( date.Value.ToShortTimeString() == System.DateTime.MinValue.ToShortTimeString() ) 
 return String.Empty;
else  
 return date.Value.ToShortTimeString();
} 

}
set 
{
if ( string.IsNullOrEmpty( value ) )  
{
 if (string.IsNullOrEmpty(date_Date)) 
{
date = null;
}
 else
{
 date = Convert.ToDateTime( " " + date.Value.ToShortDateString() + " " + System.DateTime.MinValue.ToLongTimeString() ) ;
}
}
 else
{
 if (string.IsNullOrEmpty(date_Date)) 
{
 date = Convert.ToDateTime( " " + System.DateTime.MinValue.ToShortDateString() + " " + value ) ;
}
 else
{
 date = Convert.ToDateTime( " " + date_Date + " " + value ) ;
}
}

}
}

public virtual System.DateTime? date 
{
get
{
return _date;
}
set 
{
if ( _date != value) 
{
_date = value ;
OnPropertyChanged("date");
}
}
}

public virtual System.String contents 
{
get
{
return _contents;
}
set 
{
if ( _contents != value) 
{
_contents = value ;
OnPropertyChanged("contents");
}
}
}

public virtual System.Int32? user_id 
{
get
{
if ( user != null ) 
{
_user_id = (System.Int32)user.id;
}

return _user_id;
}
set 
{
if ( _user_id != value) 
{
// Simplified Parent Access Property : reset object reference if simple property changes it's value
_user = null;

_user_id = value ;
OnPropertyChanged("user_id");
}
}
}

public virtual System.Int32? forum_id 
{
get
{
if ( forum != null ) 
{
_forum_id = (System.Int32)forum.id;
}

return _forum_id;
}
set 
{
if ( _forum_id != value) 
{
// Simplified Parent Access Property : reset object reference if simple property changes it's value
_forum = null;

_forum_id = value ;
OnPropertyChanged("forum_id");
}
}
}

public virtual System.Int32? art_id 
{
get
{
if ( art != null ) 
{
_art_id = (System.Int32)art.id;
}

return _art_id;
}
set 
{
if ( _art_id != value) 
{
// Simplified Parent Access Property : reset object reference if simple property changes it's value
_art = null;

_art_id = value ;
OnPropertyChanged("art_id");
}
}
}

public virtual System.Int32? comment_id 
{
get
{
if ( commentParent != null ) 
{
_comment_id = (System.Int32)commentParent.id;
}

return _comment_id;
}
set 
{
if ( _comment_id != value) 
{
// Simplified Parent Access Property : reset object reference if simple property changes it's value
_commentParent = null;

_comment_id = value ;
OnPropertyChanged("comment_id");
}
}
}

/// <summary>
/// Collection of comment.
/// </summary>
/// <remarks>
/// This has been automatically being generated because of the mapped 1:Many Relation 
/// </remarks>
[GenWiseAttribute(RelationID = "9829acdd-8553-4c18-b6c4-e89dada212ec" , CollectionOfType = typeof(comment)) ]
public virtual IList<comment> commentChild 
{
get
{
 if (_commentChild == null) _commentChild = new List<comment>();

return _commentChild;
}
set 
{
if ( _commentChild != value) 
{
_commentChild = value ;
}
}
}

/// <summary>
/// Generated from Relation FK_Comment_Art
/// </summary>
[GenWiseAttribute(RelationID = "baf04a50-8a61-43e2-85d9-b710c6c3e5c4") ]
public virtual art art 
{
get
{
if ( _art == null ) 
{
if ( !_art_id.HasValue || _art_id.Value.Equals(System.Int32.MinValue) ) 
{
if ( _art != null && ( _art.id.Equals(null) ) )
{
  _art = null;
}
}
else
{
_art = (new artFactory()).Get(_art_id.Value);
}
}

return _art;
}
set 
{
if ( _art != value) 
{
if ( value==null ) _art_id = null; else _art_id = (System.Int32)value.id; 
_art = value ;
}
}
}

/// <summary>
/// Generated from Relation FK_Comment_Comment
/// </summary>
[GenWiseAttribute(RelationID = "9829acdd-8553-4c18-b6c4-e89dada212ec") ]
public virtual comment commentParent 
{
get
{
if ( _commentParent == null ) 
{
if ( !_comment_id.HasValue || _comment_id.Value.Equals(System.Int32.MinValue) ) 
{
if ( _commentParent != null && ( _commentParent.id.Equals(null) ) )
{
  _commentParent = null;
}
}
else
{
_commentParent = (new commentFactory()).Get(_comment_id.Value);
}
}

return _commentParent;
}
set 
{
if ( _commentParent != value) 
{
if ( value==null ) _comment_id = null; else _comment_id = (System.Int32)value.id; 
_commentParent = value ;
}
}
}

/// <summary>
/// Generated from Relation FK_Comment_Forum
/// </summary>
[GenWiseAttribute(RelationID = "11acce2c-5e38-4fc2-a7b4-38d8642a9390") ]
public virtual forum forum 
{
get
{
if ( _forum == null ) 
{
if ( !_forum_id.HasValue || _forum_id.Value.Equals(System.Int32.MinValue) ) 
{
if ( _forum != null && ( _forum.id.Equals(null) ) )
{
  _forum = null;
}
}
else
{
_forum = (new forumFactory()).Get(_forum_id.Value);
}
}

return _forum;
}
set 
{
if ( _forum != value) 
{
if ( value==null ) _forum_id = null; else _forum_id = (System.Int32)value.id; 
_forum = value ;
}
}
}

/// <summary>
/// Generated from Relation FK_Comment_User
/// </summary>
[GenWiseAttribute(RelationID = "61b7e623-69b4-4eb0-b0e3-6df16cc1a69f") ]
public virtual user user 
{
get
{
if ( _user == null ) 
{
if ( !_user_id.HasValue || _user_id.Value.Equals(System.Int32.MinValue) ) 
{
if ( _user != null && ( _user.id.Equals(null) ) )
{
  _user = null;
}
}
else
{
_user = (new userFactory()).Get(_user_id.Value);
}
}

return _user;
}
set 
{
if ( _user != value) 
{
if ( value==null ) _user_id = null; else _user_id = (System.Int32)value.id; 
_user = value ;
}
}
}

/// <summary>
/// Is this object Valid? 
/// </summary>
/// <remarks>
/// This is achieved by counting how many errors are returned from the Validate() method. If no errors are found then it's valid.
/// </remarks>
[Bindable(false)]
public virtual System.Boolean IsValid 
{
get
{
List<Error> _errors = this.Validate(); if ( _errors.Count > 0 ) return false; else return true;
}
}


#endregion


#region --- Class Methods --- 

/// <summary>
/// Raises PropertyChanged event.
/// </summary>
protected virtual void OnPropertyChanged(System.String ppropertyChanged)
{
if (_propertyChanged != null) _propertyChanged( this , new PropertyChangedEventArgs(ppropertyChanged));

}

/// <summary>
/// Create a new comment object. 
/// </summary>
public  comment()
{
_id = System.Int32.MinValue;

}

/// <summary>
/// Add a new comment object and automatically associate it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="pcomment">An comment object to be added to this objects collection.</param>
public virtual void AddcommentChild(comment pcomment)
{
if( pcomment == null  ) throw new ArgumentNullException("pcomment");
// Set the Parent Property
pcomment.commentParent = this;
if (!pcomment.IsValid) { throw new Exception("pcomment failed on the Validate() method." + Error.ErrorsToString( pcomment.Validate() ) ); }
commentChild.Add(pcomment);
}

/// <summary>
/// Delete an existing comment object + remove the association it with this instance as it's parent. This method makes easier to add new children and ensures you do not forget to related them correctly.
/// </summary>
///<param name="pcomment">The comment object to be removed from this objects collection.</param>
public virtual void DeletecommentChild(comment pcomment)
{
if( pcomment == null  ) throw new ArgumentNullException("pcomment");
commentChild.Remove(pcomment);
// Remove the Association with the Parent object
pcomment.commentParent = null;
}

/// <summary>
/// Validates the object returning a list of errors if the validation fails.
/// </summary>
/// <remarks>
/// You can use the provided User CodeBlocks to add your own validations.
/// </remarks>
///<returns>Returns the List of Errors found during the Validation. If no errors are found null is returned.<returns>
public virtual List<Error> Validate()
{
List<Error> _errors = new List<Error>();
return _errors;
}


#endregion


#region --- Class Events  ---

public event PropertyChangedEventHandler PropertyChanged 
{
   add {
_propertyChanged+= value;
   }
   remove {
_propertyChanged-= value;
   }
}


#endregion
}
}

